import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Modify extends JPanel implements ActionListener {//改密
    private JButton backBtn;
    private JButton backBtn1;
    private Start frame;
    private Icon anj = Util.getIcon("/images/buttonOff.jpg");
    private Icon anj1 = Util.getIcon("/images/buttonSure.jpg");
    private JTextField gaiK = new JTextField();
    private JTextField gaiK1 = new JTextField();
    public Modify(Start frame) {
        this.frame = frame;
        this.setLayout(null);
        this.setOpaque(false);
        JLabel titleLabel = new JLabel("改密");
        titleLabel.setBounds(380, 10, 100, 50);
        this.add(titleLabel);

        JLabel gaiB = new JLabel("新密码：");
        gaiB.setBounds(250, 200, 150, 20);
        gaiB.setForeground(Color.WHITE);
        gaiB.setFont(new Font("楷体", Font.PLAIN, 20));
        this.add(gaiB);

        gaiK1.setBounds(350,200,100,20);
        this.add(gaiK1);

        JLabel gaiB1 = new JLabel("确认密码：");
        gaiB1.setBounds(250, 250, 150, 20);
       gaiB1.setForeground(Color.WHITE);
        gaiB1.setFont(new Font("楷体", Font.PLAIN, 20));
        this.add(gaiB1);

        gaiK.setBounds(350,250,100,20);
        this.add(gaiK);

        backBtn = new JButton(anj);
        backBtn.setBounds(450, 350, 100, 50);
        this.add(backBtn);
        backBtn.addActionListener(this);

        backBtn1 = new JButton(anj1);
        backBtn1.setBounds(250, 350, 100, 50);
        this.add(backBtn1);
        backBtn1.addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (backBtn == e.getSource()) {
            frame.switchPanel("menu");
        }else if (backBtn1==e.getSource()){
            if (gaiK.getText().equals(gaiK1.getText())) {
                frame.getUser().getInformation().get(frame.getLoginPanel().getInd()).setCode(frame.getGai().gaiK.getText());
                JOptionPane.showMessageDialog(this,"改密成功");
                frame.switchPanel("menu");
            }else {
                JOptionPane.showMessageDialog(this,"两次密码不一致");
            }
        }
    }
}
